module.exports = function ($scope, $state, $resource,$modal, toaster) {

  /* 分页
      * ========================================= */
      $scope.maxSize = 5;            //最多显示多少个按钮
      $scope.bigCurrentPage = 1;      //当前页码
      $scope.itemsPerPage = 10;         //每页显示几条
      $scope.searchform = {};
    
      $scope.load = function () {
          var para = {
            // eq_name:$scope.searchform.eq_name,
            pageNo: $scope.bigCurrentPage,
            pageSize: $scope.itemsPerPage,
          };
          para = angular.extend($scope.searchform, para);
          $resource('/api/as/ac/evaluation/findCompanyPageList', {}, {}).save(para,function (res) {
    
            if (res.errcode !== 0) {
              alert("数据获取失败");
              return;
            }
      
            $scope.objs = res.data.results;
            $scope.bigTotalItems = res.data.totalRecord;
            $scope.bigCurrentPage = res.data.pageNo;
      
          });
      };
    $scope.load();



    $scope.eqstart = function (code) {
      $resource('/api/as/ac/evaluation/updateCompanyStateUp', {}, {}).save({'id':code},function (res) {
        if (res.errcode === 0) {
          toaster.success({ title: "提示", body: "启用成功！"});
          $scope.load();
        } else {
          toaster.error({ title: "提示", body: res.errmsg });
        }
      });
    }

    $scope.eqstop = function (code) {
      $resource('/api/as/ac/evaluation/updateCompanyStateDown', {}, {}).save({'id':code},function (res) {
        if (res.errcode === 0) {
          toaster.success({ title: "提示", body: "停用成功！"});
          $scope.load();
        } else {
          toaster.error({ title: "提示", body: res.errmsg });
        }
      });
    }

    $scope.del = function (code) {
      if(confirm("您确认要删除吗？")){
      $resource('/api/as/ac/evaluation/updateCompanyDel', {}, {}).save({'id':code},function (res) {
        if (res.errcode === 0) {
          toaster.success({ title: "提示", body: "删除成功！"});
          $scope.load();
        } else {
          toaster.error({ title: "提示", body: res.errmsg });
        }
      });
    }
  }
    

    $scope.add = function (id){
      var modalInstance = $modal.open({
        template: require('../views/addenterprise.html'),
        controller: 'addenterprise',
        size: 'xs',
        resolve: {
          id:function(){
            return id;
          },
          flag : function () {
            return id == 1;
          },
        }
    });
    modalInstance.result.then(function (showResult) {	
      $scope.load();
    });
    }

    $scope.qcode = function(code){
      var qrcode = ""
      console.log(window.location.href);
      if(window.location.href=='https://tsv.juyouhx.com/#!/app/satisfaction/qyelist'){
        qrcode = "https://weixint.juyouhx.com/views/evaluate/article.html?cid=tz001491c52a25a4a&company_id="+code;
      }else{
        qrcode = "https://dlqt.juyouhx.com/views/evaluate/article.html?cid=tz001491c52a25a4a&company_id="+code;
      }
     
      var modalInstance = $modal.open({
        template: require('../views/qyeqrcode.html'),
        controller: 'qyeqrcode',
        size: 'xs',
        resolve: {
          qrcode: function () {
            return qrcode;
          }
        }
      });
      modalInstance.result.then(function () {
        $scope.load();
      });
    }
    $scope.wxqcode = function(code){
      var qrcode = code;
      var modalInstance = $modal.open({
        template: require('../views/qyeqrcode.html'),
        controller: 'qyeqrcode',
        size: 'xs',
        resolve: {
          qrcode: function () {
            return qrcode;
          }
        }
      });
      modalInstance.result.then(function () {
        $scope.load();
      });
    }

    $scope.ins = function() {
      if(window.location.href=='https://tsv.juyouhx.com/#!/app/satisfaction/qyelist'){
        $.ajax({
          type:'POST',
          url:'https://txy.juyouhx.com/Api/Api/createMydQrcode',
          data:{
          },
          lg:true,
          success: function(ret){
              console.log(ret);
              toaster.success({ title: "提示", body: "添加成功！"});
              $scope.load();
          }
      })
      }else{
        $.ajax({
          type:'POST',
          url:'https://dlqt.juyouhx.com/Api/Api/createMydQrcode',
          data:{
          },
          lg:true,
          success: function(ret){
              console.log(ret);
              toaster.success({ title: "提示", body: "添加成功！"});
              $scope.load();
          }
      })
      }
      
    }
  };


